<template>
	<view class="container" :data-theme="theme">
		<view class="header"><!-- 商品详情 -->
			<view class="gift-type-card" v-if="goodsOrCategoryInfo && goodsOrCategoryInfo.id">
				<view class="gift-type" style="display: flex;justify-content: space-between;align-items: center;">
					<view class="gift-type-left">
						开启状态
					</view>
					<view class="gift-type-right">
						<switch :checked="checkedObj.isShow" @change="changeIsShow" />
					</view>
				</view>
			</view>
			<view class="gift-type-card" v-if="goodsOrCategoryInfo && goodsOrCategoryInfo.id">
				<view class="gift-type" style="display: flex;justify-content: space-between;align-items: center;">
					<view class="gift-type-left">
						商品/品类信息
					</view>
					<view class="gift-type-right">
						<button :style="{color: bgColor,}" @click="handleDetail">查看详情</button>
					</view>
				</view>
			</view>

		</view>
		<view class="content">
			<!-- 这里是可滚动的内容 -->
			<scroll-view class="scroll-view" scroll-y>
				<view class="scroll-view-inner">
					<!-- 售卖区域 -->
					<view class="sale-area-card">
						<view class="sale-area">
							<view class="sale-area-left">售卖区域</view>
							<view class="sale-area-right">
								<uni-data-picker placeholder="请选择售卖区域" popup-title="请选择所在地区" :localdata="cityCodeList"
									v-model="classes" @change="onchange">
								</uni-data-picker>
							</view>
						</view>
					</view>
					<!-- 商品活动 -->
					<view class="product-active-card">
						<!-- 活动时间 -->
						<view class="active-time">
							<view class="active-time-left">活动时间</view>
							<view class="active-time-right">
								<uni-datetime-picker v-model="depreciatePromotion.activityTimeList" type="daterange"
									@change="changeActiveTime">
									<view v-if="depreciatePromotion.activityTime">{{depreciatePromotion.activityTime}}
									</view>
									<view v-else>请选择活动时间</view>
								</uni-datetime-picker>
								<u-icon name="arrow-right"></u-icon>
							</view>
						</view>
						<!-- 商品范围 -->
						<view class="product-scope">
							<view class="product-scope-left">商品范围</view>
							<view class="product-scope-right">
								<view class="product-type" :class="{'active' : index == productScopeIndex}"
									v-for="(item,index) in productScopeList" :key="index"
									@click="clickProductType(index)">
									{{item.name}}
								</view>
							</view>
						</view>
						<!-- 单客户限购单数 -->
						<view class="active-limit-card">
							<view class="active-limit-top">
								<view class="active-limit-left">单客户限购单数 <uni-icons type="info" size="20"></uni-icons>
								</view>
								<view class="active-limit-right">
									<view class="active-type" :class="{'active' : index == dateLimitShopIndex}"
										v-for="(item,index) in dateLimitShopList" :key="index"
										@click="clickDateLimitShop(index)">
										{{item.name}}
									</view>
								</view>
							</view>
							<view class="active-limit-bottom" v-if="dateLimitShopIndex == 1">
								<uni-number-box v-model="depreciatePromotion.activeLimit.dateLimitShopNum" />
							</view>
						</view>

						<!-- 满赠方式 -->
						<view class="product-scope">
							<view class="product-scope-left">满赠方式<uni-icons type="info" size="20"></uni-icons></view>
							<view class="product-scope-right">
								<view class="product-type" :class="{'active' : index == giveMethodsIndex}"
									v-for="(item,index) in giveMethodsList" :key="index"
									@click="clickGiveMethods(index)">
									{{item.name}}
								</view>
							</view>
						</view>

					</view>

					<!-- 赠送类型 -->
					<view class="gift-type-card">
						<view class="gift-type">
							<view class="gift-type-left">
								<span
									:style="{color: 'white',backgroundColor: bgColor,marginRight:'10rpx',padding: '0 5rpx'}">赠</span>
							</view>
							<view class="gift-type-right">
								<view v-for="(item,index) in depreciatePromotion.discountsList" :key="index"
									style="margin-bottom: 10rpx;">
									满
									<span>{{item.condition ? item.condition : '_'}}</span>{{giveMethodsIndex == 0 ? '元' : '件'}}赠【
									<span>{{depreciatePromotion.discountsList[index].giftProductInfo.name}}</span>
									】<span>{{item.giftPieceNum ? item.giftPieceNum : '_'}}</span>件
								</view>
							</view>
						</view>
					</view>

					<!-- 优惠阶梯 -->
					<view class="discounts-card">
						<view class="discounts-item" v-for="(item,index) in depreciatePromotion.discountsList"
							:key="index">
							<view class="discounts-item-title">
								<view class="item-title-left">
									优惠阶梯{{index + 1}}
								</view>
								<view class="item-title-right" @click="handleDelete(index)"
									v-if="depreciatePromotion.discountsList.length != 1">
									<u-icon name="trash-fill" size="26"></u-icon>
								</view>
							</view>
							<!-- 金额满 -->
							<view class="discounts">
								<view class="discounts-top">
									<view class="discounts-left"> {{giveMethodsIndex == 0 ? '金额满' : '商品件数满'}} </view>
									<view class="discounts-right">
										<input type="number" placeholder="请输入" v-model="item.condition"
											@input="inputMoneyNum(index)" class="right-input" />
										{{giveMethodsIndex == 0 ? '元' : '件'}}
									</view>
								</view>
								<view class="discounts-bottom" v-if="item.moneyNumShow">
									{{giveMethodsIndex == 0 ? '门榄金额不能大于9999' : '商品门榄件数不能大于9999'}}
								</view>
								<view class="discounts-bottom" v-if="item.moneyNumDataShow">门榄金额不能为空</view>
							</view>
							<!-- 赠品 -->
							<view class="discounts">
								<view class="discounts-top">
									<view class="discounts-left">赠品</view>
									<view class="discounts-right" @click="selectionProduct(0,index)">
										<span class="font_color">请选择</span><u-icon :color="bgColor"
											name="arrow-right"></u-icon>
									</view>
								</view>
								<view class="productName-bottom">
									{{item.giftProductInfo.name}}
								</view>
								<!-- 满赠送 -->
								<view class="discounts-bottom" style="font-size: 26rpx;"
									v-if="item.giftProductInfoShow && giveMethodsIndex == 0">
									赠品总价值{{Number(item.giftProductInfo.price)*Number(item.giftPieceNum)}}元(赠品原价{{item.giftProductInfo.price}}*赠送件数{{item.giftPieceNum}})已高于门榄金额
								</view>
								<!-- 满件送 -->
								<view class="discounts-bottom" style="font-size: 26rpx;"
									v-if="item.giftProductInfoShow && giveMethodsIndex == 1">
									赠品总价值{{Number(item.giftProductInfo.price)*Number(item.giftPieceNum)}}元(赠品原价{{item.giftProductInfo.price}}*赠送件数{{item.giftPieceNum}})已高于门榄件数
								</view>
								<view class="discounts-bottom" v-if="item.giftProductInfoDataShow">请选择赠品</view>
							</view>
							<!-- 赠送件数 -->
							<view class="discounts">
								<view class="discounts-top">
									<view class="discounts-left">赠送件数<uni-icons type="info" size="20"></uni-icons>
									</view>
									<view class="discounts-right">
										<input type="number" placeholder="请输入" v-model="item.giftPieceNum"
											class="right-input" @input="inputGiftPieceNum(index)" />
										件
									</view>
								</view>
								<view class="discounts-bottom" v-if="item.giftPieceNumShow">
									赠送件数不能大于5
								</view>
								<view class="discounts-bottom" v-if="item.giftPieceNumDataShow">赠送件数不能为空</view>
							</view>
							<!-- 赠品活动库存 -->
							<view class="discounts">
								<view class="discounts-top">
									<view class="discounts-left">赠品活动库存<uni-icons type="info" size="20"></uni-icons>
									</view>
									<view class="discounts-right">
										<input type="number" v-model="item.giftRepertoryNum" placeholder="请输入"
											@input="inputGiftRepertoryNum(index)" class="right-input" />
										件
									</view>
								</view>
								<view class="discounts-bottom" v-if="item.giftRepertoryNumShow">
									赠品活动库存数不能大于99999
								</view>
								<view class="discounts-bottom" v-if="item.giftRepertoryNumDataShow">赠送活动库存不能为空</view>
							</view>
						</view>
						<!-- 新增阶梯 -->
						<view class="ladder-card font_color" @click="addLadder"
							v-if="depreciatePromotion.discountsList.length < 3">
							+新增阶梯{{depreciatePromotion.discountsList.length}}/3
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="footer">
			<checkbox-group @change="requiredChange">
				<label class="footer-required">
					<view>
						<checkbox :checked="required" />
					</view>
					<view>已阅读并同意 <span class="font_color">《合作商自营销协议》</span> </view>
				</label>
			</checkbox-group>

			<button class="bg_color" @click="handleNext" shape="circle"
				style="padding: 20rpx;">{{productScopeIndexObj[productScopeIndex]}}</button>
		</view>
	</view>
</template>
<script>
	import {
		setThemeColor
	} from '../../../utils/setTheme';
	import {
		queryBusinessOperateCityApi
	} from "@/api/operateCity.js"
	import {
		getCityTreeListApi,
		addActivityRegistrationApi,
		getNoRegistrationActivityApi
	} from "@/api/marketing.js"
	let app = getApp()
	export default {
		data() {
			return {
				bgColor: "#fff",
				theme: app.globalData.theme,
				depreciatePromotion: {
					activityTime: null, // 活动时间
					activityTimeList: [], // 活动时间
					saleAreaList: [], // 售卖区域
					activeLimit: {
						dateLimitShopNum: '', // 日限购 自定义数量
						dateLimitShop: true, // 日限购
					},
					// 优惠阶梯
					discountsList: [{
						condition: '', //金额满、件数
						moneyNumShow: false, // 金额满/商品件数满提示信息
						giftPieceNum: '', // 赠送件数
						giftPieceNumShow: false, // 赠送件数提示信息
						giftRepertoryNum: '', // 赠送库存
						giftRepertoryNumShow: false, // 赠送库存提示信息
						giftProductInfo: {}, // 赠送商品
						giftProductInfoShow: false, // 赠送商品
						// 判断有没有数据
						moneyNumDataShow: false, // 金额满/商品件数满空数据提示信息
						giftPieceNumDataShow: false, // 赠送件数空数据提示信息
						giftRepertoryNumDataShow: false, // 赠送库存空数据提示信息
						giftProductInfoDataShow: false, // 赠送商品空数据提示信息
					}],
				},
				// ----------------------------商品范围----------------------
				productScopeList: [{
						name: '全店',
						value: 0
					},
					{
						name: '部分商品',
						value: 1
					},
					{
						name: '部分品类',
						value: 2
					},
				],
				productScopeIndex: 0,
				productScopeIndexObj: {
					0: '确认创建',
					1: '下一步，选择门槛商品',
					2: '下一步，选择门槛品类',
				},
				// ----------------------------end----------------------
				// ----------------------------单客户限购单数----------------------
				dateLimitShopList: [{
						name: '不限制',
						value: 1
					},
					{
						name: '自定义',
						value: 2
					},
				],
				dateLimitShopIndex: 0,
				// ----------------------------end----------------------
				// ----------------------------满赠方式----------------------
				giveMethodsList: [{
						name: '满赠送',
						value: 3
					},
					{
						name: '满件送',
						value: 4
					},
				],
				giveMethodsIndex: 0,
				// ----------------------------end----------------------
				required: false,
				configInfo: {}, // 活动配置信息
				// ------------------------------售卖区域-------------------
				cityCodeList: [], // 城市信息
				classes: null,
				// ----------------------------end----------------------------
				// ------------------------回显数据-------------------
				// 商品满赠信息
				goodsOrCategoryInfo: {},
				// 通用赠品信息
				generalGiftInfo: {},
				// 开启状态
				checkedObj: {
					isShow: false
				}
			}
		},
		onLoad(options) {
			this.bgColor = setThemeColor()
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: this.bgColor,
			});
			// 获取售卖区域
			this.initData()
		},
		methods: {
			// 初始化数据
			initData() {
				this.getNoRegistrationActivity()
				this.getCityTreeList()
			},
			// 回显数据
			echoData() {
				// 开启状态
				this.$set(this.checkedObj, 'isShow', this.goodsOrCategoryInfo.isShow)
				// 回显时间
				let timeList = this.goodsOrCategoryInfo.activityTimeList
				this.depreciatePromotion.activityTimeList = timeList
				this.depreciatePromotion.activityTime = timeList[0].slice(0, 10) + '至' + timeList[1].slice(0, 10) + '(' +
					'共' +
					this
					.calculateDaysBetweenDates(timeList[0], timeList[
						1]) + '天)'
				this.productScopeIndex = this.goodsOrCategoryInfo.productScope
				// 单客户限购单数
				if (this.goodsOrCategoryInfo.customerDailyLimit == -1) {
					this.dateLimitShopIndex = 0
				} else {
					this.dateLimitShopIndex = 1
					this.$set(this.depreciatePromotion.activeLimit, 'dateLimitShopNum', this.goodsOrCategoryInfo
						.customerDailyLimit)
				}
				// 售卖区域
				this.classes = this.goodsOrCategoryInfo.activityScopeList[0][1]
				this.depreciatePromotion.saleAreaList = this.goodsOrCategoryInfo.activityScopeList
				// 满赠方式
				this.giveMethodsIndex = Number(this.goodsOrCategoryInfo.activitySubsidyList[0].type) - 3
				// 满赠优惠信息
				this.depreciatePromotion.discountsList = this.goodsOrCategoryInfo.activitySubsidyList.map(item => {
					return {
						condition: item.condition, //金额满
						moneyNumShow: false, // 金额满/商品件数满提示信息
						giftPieceNum: item.subsidy, // 赠送件数
						giftPieceNumShow: false, // 赠送件数提示信息
						giftRepertoryNum: item.stock, // 赠送库存
						giftRepertoryNumShow: false, // 赠送库存提示信息
						giftProductInfo: {
							id: item.skuId,
							name: item.name,
							price: item.price,
							operateCityId: item.operateCityId

						}, // 赠送商品
						giftProductInfoShow: false, // 赠送商品
						// 判断有没有数据
						moneyNumDataShow: false, // 金额满/商品件数满空数据提示信息
						giftPieceNumDataShow: false, // 赠送件数空数据提示信息
						giftRepertoryNumDataShow: false, // 赠送库存空数据提示信息
						giftProductInfoDataShow: false, // 赠送商品空数据提示信息
					}

				})
			},
			// ------------------------------end----------------------------
			// 查看详情
			handleDetail() {
				uni.navigateTo({
					url: `/pages/marketing/fullGiftList/components/productDetail?cityCodeList=${JSON.stringify(this.cityCodeList)}`,
				});
			},
			// -----------------------------售卖区域----------------------
			// 选择售卖区域城市
			onchange(e) {
				if (e.detail.value.length) {
					this.depreciatePromotion.saleAreaList = [
						[
							e.detail.value[0].value, e.detail.value[1].value
						]
					]
				}
			},
			calculateDaysBetweenDates(date1Str, date2Str) {
				// 将日期字符串转换为 Date 对象
				var date1 = new Date(date1Str);
				var date2 = new Date(date2Str);

				// 计算两个日期的时间戳（单位：毫秒）
				var time1 = date1.getTime();
				var time2 = date2.getTime();

				// 确保 date1 <= date2，如果不是，则交换两个日期
				if (time1 > time2) {
					var temp = date1;
					date1 = date2;
					date2 = temp;
				}

				// 设置 date1 的时分秒为 00:00:00
				date1.setHours(0, 0, 0, 0);

				// 设置 date2 的时分秒为 00:00:00，并将日期加一天，用于确保计算包含 date2 这一天
				date2.setHours(0, 0, 0, 0);
				date2.setDate(date2.getDate() + 1);

				// 计算两个日期之间的天数差
				var timeDiff = date2.getTime() - date1.getTime();
				var daysDiff = Math.floor(timeDiff / (1000 * 60 * 60 * 24));

				return daysDiff;
			},
			// 改变活动时间
			changeActiveTime(e) {
				this.depreciatePromotion.activityTime = e[0] + '至' + e[1] + '(共' + this.calculateDaysBetweenDates(e[0], e[
					1]) + '天)'
				this.depreciatePromotion.activityTimeList = [e[0] + ' 00:00:00', e[1] + ' 23:59:59']
			},
			// -----------------------------商品范围------------------
			clickProductType(index) {
				this.productScopeIndex = index
			},
			// 单客户限购单数
			clickDateLimitShop(index) {
				this.dateLimitShopIndex = index
			},
			// 满赠方式
			clickGiveMethods(index) {
				this.giveMethodsIndex = index
				// 切换满赠方式校验优惠阶梯
				this.depreciatePromotion.discountsList.forEach((item, index) => {
					// 金额满，商品件数满提示
					this.inputMoneyNum(index)
					// 赠送件数提示
					this.inputGiftPieceNum(index)
				})
			},

			// -------------------------------优惠阶梯----------------------------------
			// 选择商品
			// index  商品选择范围
			// discountsIndex  优惠阶梯下标
			selectionProduct(index, discountsIndex) {
				if (index == 1) {
					this.generalGift()
					// 组合活动配置信息
					const activityTime = this.depreciatePromotion.activityTime.replace(/\(.*?\)/, "");
					this.configInfo = {
						activityTime,
						giveMethodsIndex: this.giveMethodsIndex,
						discountsList: this.depreciatePromotion.discountsList
					}
					// 删除部分品类
					let partCategoryList = []
					if (this.goodsOrCategoryInfo.productScope == 2) {
						partCategoryList = this.goodsOrCategoryInfo
							.enrolledActivityProductVoList.map(item => {
								return {
									businessSign: 3,
									enrolledActivityId: item.enrolledActivityId
								}
							})
					}
					uni.navigateTo({
						url: `/pages/marketing/fullGiftList/components/promotionProduct?productScopeIndex=${index}&discountsIndex=${discountsIndex}&configInfo=${JSON.stringify(this.configInfo)}&generalGiftInfo=${JSON.stringify(this.generalGiftInfo)}&partCategoryList=${JSON.stringify(partCategoryList)}`,
					})
				} else {
					// 商品选择范围
					uni.navigateTo({
						url: `/pages/marketing/fullGiftList/components/promotionProduct?productScopeIndex=${index}&discountsIndex=${discountsIndex}`

					})
				}

			},
			// 优惠阶梯添加商品
			addDiscountsProduct(threeProductList) {
				this.depreciatePromotion.discountsList[threeProductList[0].discountsIndex].giftProductInfo =
					threeProductList[0]
				this.giftProductHint(threeProductList[0].discountsIndex)
				// 有商品将空商品校验取消
				this.depreciatePromotion.discountsList[threeProductList[0].discountsIndex].giftProductInfoDataShow = false
			},
			// 通用判断赠品价格是否高于满赠价格
			giftProductHint(index) {
				let item = this.depreciatePromotion.discountsList[index]
				if (item.giftProductInfo.name && item.giftPieceNum && item.condition && (
						Number(item.giftProductInfo.price) * Number(item.giftPieceNum) > Number(item
							.condition))) {
					this.depreciatePromotion.discountsList[index].giftProductInfoShow = true
				} else {
					this.depreciatePromotion.discountsList[index].giftProductInfoShow = false
				}
			},
			// 通用判断赠品件数是否高于满赠件数
			giftProductCountHint(index) {
				let item = this.depreciatePromotion.discountsList[index]
				if (item.giftProductInfo.name && item.giftPieceNum && item.condition && (
						Number(item.giftPieceNum) > Number(item
							.condition))) {
					this.depreciatePromotion.discountsList[index].giftProductInfoShow = true
				} else {
					this.depreciatePromotion.discountsList[index].giftProductInfoShow = false
				}
			},
			// 通用判断数据是否为空
			isDataEmpty(index, num, dataShow) {
				if (!this.depreciatePromotion.discountsList[index][num]) {
					this.depreciatePromotion.discountsList[index][dataShow] = true
				} else {
					this.depreciatePromotion.discountsList[index][dataShow] = false
				}
			},
			// 金额满，商品件数满提示
			inputMoneyNum(index) {
				if (this.depreciatePromotion.discountsList[index].condition > 9999) {
					this.depreciatePromotion.discountsList[index].moneyNumShow = true
				} else {
					this.depreciatePromotion.discountsList[index].moneyNumShow = false
				}
				// 判断赠送方式是满赠送还是满件送
				if (this.giveMethodsIndex == 0) {
					//满赠送
					this.giftProductHint(index)
				} else if (this.giveMethodsIndex == 1) {
					// 满件送
					this.giftProductCountHint(index)
				}
				this.isDataEmpty(index, 'condition', 'moneyNumDataShow')
			},
			// 赠送件数提示
			inputGiftPieceNum(index) {
				if (this.depreciatePromotion.discountsList[index].giftPieceNum > 5) {
					this.depreciatePromotion.discountsList[index].giftPieceNumShow = true
				} else {
					this.depreciatePromotion.discountsList[index].giftPieceNumShow = false
				}
				// 判断赠送方式是满赠送还是满件送
				if (this.giveMethodsIndex == 0) {
					//满赠送
					this.giftProductHint(index)
				} else if (this.giveMethodsIndex == 1) {
					// 满件送
					this.giftProductCountHint(index)
				}
				// 判断赠送件数是否为空
				this.isDataEmpty(index, 'giftPieceNum', 'giftPieceNumDataShow')
			},
			// 赠送活动库存提示
			inputGiftRepertoryNum(index) {
				if (this.depreciatePromotion.discountsList[index].giftRepertoryNum > 99999) {
					this.depreciatePromotion.discountsList[index].giftRepertoryNumShow = true
				} else {
					this.depreciatePromotion.discountsList[index].giftRepertoryNumShow = false
				}
				// 判断赠送活动库存是否为空
				this.isDataEmpty(index, 'giftRepertoryNum', 'giftRepertoryNumDataShow')
			},

			// 删除阶梯
			handleDelete(index) {
				this.depreciatePromotion.discountsList.splice(index, 1)
			},
			// 新增阶梯
			addLadder() {
				if (this.depreciatePromotion.discountsList.length < 3) {
					this.depreciatePromotion.discountsList.push({
						condition: '', //金额满
						moneyNumShow: false, // 金额满/商品件数满提示信息
						giftPieceNum: '', // 赠送件数
						giftPieceNumShow: false, // 赠送件数提示信息
						giftRepertoryNum: '', // 赠送库存
						giftRepertoryNumShow: false, // 赠送库存提示信息
						giftProductInfo: {}, // 赠送商品
						// 判断有没有数据
						moneyNumDataShow: false, // 金额满/商品件数满空数据提示信息
						giftPieceNumDataShow: false, // 赠送件数空数据提示信息
						giftRepertoryNumDataShow: false, // 赠送库存空数据提示信息
						giftProductInfoDataShow: false, // 赠送商品空数据提示信息
					})
				} else {
					uni.showToast({
						title: '最多添加三个阶梯',
						icon: 'none',
						duration: 1500
					})
				}
			},
			// 必选事件
			requiredChange(val) {
				this.required ? this.required = false : this.required = true
			},
			// 通过函数判断所有优惠阶梯是否都有值并且校验通过
			checkArrayObjectsProperties(array) {
				for (let i = 0; i < array.length; i++) {
					const obj = array[i];
					// 金额满/商品件数满空数据提示信息
					if (!obj.condition) {
						this.depreciatePromotion.discountsList[i].moneyNumDataShow = true
					}
					//赠送件数空数据提示信息
					if (!obj.giftPieceNum) {
						this.depreciatePromotion.discountsList[i].giftPieceNumDataShow = true
					}
					// 赠送库存空数据提示信息
					if (!obj.giftRepertoryNum) {
						this.depreciatePromotion.discountsList[i].giftRepertoryNumDataShow = true
					}
					// 赠送商品空数据提示信息
					if (Object.keys(obj.giftProductInfo).length === 0) {
						this.depreciatePromotion.discountsList[i].giftProductInfoDataShow = true
					} else {
						this.depreciatePromotion.discountsList[i].giftProductInfoDataShow = false
					}
					// 检查每个属性是否有值并且为 false
					if (obj.condition === '' ||
						obj.moneyNumShow !== false ||
						obj.giftPieceNum === '' ||
						obj.giftPieceNumShow !== false ||
						obj.giftRepertoryNum === '' ||
						obj.giftRepertoryNumShow !== false ||
						Object.keys(obj.giftProductInfo).length === 0 ||
						obj.giftProductInfoShow !== false) {
						// 如果有任何一个属性不符合条件，则返回 false
						return false;
					}
				}
				// 如果所有对象的所有属性都符合条件，则返回 true
				return true;
			},
			// 通用赠品信息组合数据
			generalGift() {
				// 商品信息
				let activitySubsidyList = this.depreciatePromotion.discountsList.map(item => {
					// 如果有id为修改  那么不能传  businessSign: 1,
					if (this.goodsOrCategoryInfo && this.goodsOrCategoryInfo.id) {
						return {
							type: this.giveMethodsList[this.giveMethodsIndex]
								.value, //活动补贴type 1、满金额减 2、满金额扣减比例 3、满金额赠 4、满件数赠
							condition: item.condition, //条件：金额、件数
							skuId: item.giftProductInfo.id, // 赠品skuId
							subsidy: item.giftPieceNum, //补贴：扣减金额、扣减比例、赠送件数
							stock: item.giftRepertoryNum, //赠品库存
							operateCityId: item.giftProductInfo.operateCityId,
							name: item.giftProductInfo.name
						}
					} else {
						return {
							businessSign: 1, // 1添加  2编辑 3删除
							type: this.giveMethodsList[this.giveMethodsIndex]
								.value, //活动补贴type 1、满金额减 2、满金额扣减比例 3、满金额赠 4、满件数赠
							condition: item.condition, //条件：金额、件数
							skuId: item.giftProductInfo.id, // 赠品skuId
							subsidy: item.giftPieceNum, //补贴：扣减金额、扣减比例、赠送件数
							stock: item.giftRepertoryNum, //赠品库存
							operateCityId: item.giftProductInfo.operateCityId,
							name: item.giftProductInfo.name

						}
					}

				})
				this.generalGiftInfo = {
					activityCategory: 8, // 默认是店铺满赠
					activityTimeList: this.depreciatePromotion.activityTimeList, // 活动时间
					activityScopeList: this.depreciatePromotion.saleAreaList, // 售卖区域
					productScope: this.productScopeList[this.productScopeIndex].value, // 商品范围
					customerDailyLimit: this.dateLimitShopIndex == 0 ? -1 : Number(this
						.depreciatePromotion.activeLimit.dateLimitShopNum), //  单客户限制单数
					activitySubsidyList: activitySubsidyList,
				}
				if (this.goodsOrCategoryInfo && this.goodsOrCategoryInfo.id) {
					this.generalGiftInfo.id = this.goodsOrCategoryInfo.id
				}


			},

			// 确认按钮
			handleNext() {

				if (!this.depreciatePromotion.saleAreaList.length) {
					return uni.showToast({
						title: '请选择售卖区域',
						duration: 1500,
						icon: 'none'
					});
				}
				if (!this.depreciatePromotion.activityTime) {
					return uni.showToast({
						title: '请选择活动时间',
						duration: 1500,
						icon: 'none'
					});
				}
				if (!this.required) {
					return uni.showToast({
						title: '请先阅读并同意《合作商自营销协议》',
						duration: 1500,
						icon: 'none'
					});
				}
				if (this.checkArrayObjectsProperties(this.depreciatePromotion.discountsList)) {
					// 全店
					if (this.productScopeIndex == 0) {
						uni.showModal({
							title: '提示',
							content: '确认创建该赠品信息吗？',
							success: (res) => {
								if (res.confirm == true) {
									this.addActivityRegistration()
								} else {
									uni.showToast({
										title: '已取消',
										icon: 'none',
										duration: 2000
									})
								}
							}
						})
						// 部分商品
					} else if (this.productScopeIndex == 1) {
						if (this.checkArrayObjectsProperties(this.depreciatePromotion.discountsList)) {

							// 选择部分商品
							this.selectionProduct(1)
						} else {
							return uni.showToast({
								title: '请完成校验',
								duration: 1500,
								icon: 'none'
							});
						}
						// 部分品类
					} else if (this.productScopeIndex == 2) {
						// 选择部分品类
						this.generalGift()
						// 选择的品类信息
						// this.generalGiftInfo.proCategoryCacheVoList = this.goodsOrCategoryInfo.proCategoryCacheVoList
						let partGoodsList = []
						// 删除部分商品
						if (this.goodsOrCategoryInfo.productScope == 1) {
							partGoodsList = this.goodsOrCategoryInfo
								.enrolledActivityProductVoList.map(item => {
									return {
										businessSign: 3,
										enrolledActivityId: item.enrolledActivityId
									}
								})
						}
						uni.navigateTo({
							url: `/pages/marketing/fullGiftList/components/goodsCategory?generalGiftInfo=${JSON.stringify(this.generalGiftInfo)}&partGoodsList=${JSON.stringify(partGoodsList)}`,
						});
					}
				} else {
					return uni.showToast({
						title: '请完成校验',
						duration: 1500,
						icon: 'none'
					});
				}
			},
			// 修改开启状态
			changeIsShow(e) {
				let that = this
				let statusInfo = e.detail.value ? '开启' : '关闭'
				that.$set(that.checkedObj, 'isShow', e.detail.value)
				uni.showModal({
					title: '提示',
					content: `确认${statusInfo}吗?`,
					success: (res) => {
						if (res.confirm == true) {
							let data = {
								activityCategory: 8, // 默认是店铺满赠
								activityTimeList: that.depreciatePromotion.activityTimeList, // 活动时间
								activityScopeList: that.depreciatePromotion.saleAreaList, // 售卖区域
								productScope: that.productScopeList[that.productScopeIndex].value, // 商品范围
								customerDailyLimit: that.dateLimitShopIndex == 0 ? -1 : Number(that
									.depreciatePromotion.activeLimit.dateLimitShopNum), //  单客户限制单数
								isShow: e.detail.value
							}
							if (that.goodsOrCategoryInfo && that.goodsOrCategoryInfo.id) {
								data.id = that.goodsOrCategoryInfo.id
							}
							that.changeIsShowActivityRegistration(data, e.detail.value)
						} else {
							that.$set(that.checkedObj, 'isShow', !e.detail.value)
							uni.showToast({
								title: '已取消',
								icon: 'none',
								duration: 2000
							})
						}
					}
				})
				console.log("e", e)
			},
			// -------------------------------api-----------------------------------------

			// 修改开启状态功能
			async changeIsShowActivityRegistration(data, isShow) {
				let that = this
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				try {
					let res = await addActivityRegistrationApi(data)
					if (res.code == 200) {
						uni.showToast({
							title: '创建成功',
							icon: 'success',
							duration: 2000
						})
						that.getNoRegistrationActivity()
					} else {
						that.$set(that.checkedObj, 'isShow', !isShow)
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 1500
						})
					}
				} catch (e) {
					uni.showToast({
						title: e,
						icon: 'none',
						duration: 1500
					})
					//TODO handle the exception
					console.log("e", e)
				}
				uni.hideLoading()
			},
			// 添加店铺满赠活动
			async addActivityRegistration() {
				let that = this
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				try {
					// 整理赠品信息
					this.generalGift()
					// 删除部分商品
					if (this.goodsOrCategoryInfo && this.goodsOrCategoryInfo.productScope == 1) {
						this.generalGiftInfo.addEnrolledActivityProductDTOList = this.goodsOrCategoryInfo
							.enrolledActivityProductVoList.map(item => {
								return {
									businessSign: 3,
									enrolledActivityId: item.enrolledActivityId
								}
							})
					}
					// 删除部分品类
					if (this.goodsOrCategoryInfo && this.goodsOrCategoryInfo.productScope == 2) {
						this.generalGiftInfo.addEnrolledActivityProductDTOList = this.goodsOrCategoryInfo
							.enrolledActivityProductVoList.map(item => {
								return {
									businessSign: 3,
									enrolledActivityId: item.enrolledActivityId
								}
							})
					}
					let res = await addActivityRegistrationApi(this.generalGiftInfo)
					if (res.code == 200) {
						uni.showToast({
							title: '创建成功',
							icon: 'success',
							duration: 2000
						})
						that.getNoRegistrationActivity()
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 1500
						})
					}
				} catch (e) {
					uni.showToast({
						title: e,
						icon: 'none',
						duration: 1500
					})
					//TODO handle the exception
					console.log("e", e)
				}
				uni.hideLoading()
			},
			// 获取活动商品信息
			async getNoRegistrationActivity() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				try {
					let res = await getNoRegistrationActivityApi(8)
					if (res.code == 200) {
						this.goodsOrCategoryInfo = res.data
						// 判断是否有数据
						if (this.goodsOrCategoryInfo && this.goodsOrCategoryInfo.id) {
							this.echoData()
						}
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 2000
						});
					}
				} catch (e) {
					//TODO handle the exception
					uni.showToast({
						title: e,
						duration: 2000,
						icon: 'none'
					})
				}
				uni.hideLoading()
			},
			// 获取城市信息
			async getCityTreeList() {
				let that = this;
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				try {
					let res = await getCityTreeListApi()
					if (res.code == 200) {
						const result = [];
						// 遍历数组中的每个对象
						for (const item of res.data) {
							// 提取对象的基本信息
							const extractedItem = {
								value: item.regionId,
								// parentId: item.parentId,
								text: item.regionName,
								// regionType: item.regionType
							};

							// 如果对象包含子对象，则将子对象的基本信息也提取出来
							if (item.child && item.child.length > 0) {
								extractedItem.children = [];
								for (const childItem of item.child) {
									const extractedChildItem = {
										value: childItem.regionId,
										// parentId: childItem.parentId,
										text: childItem.regionName,
										// regionType: childItem.regionType
									};
									extractedItem.children.push(extractedChildItem);
								}
							}
							// 将提取的对象添加到结果数组中
							result.push(extractedItem);
						}
						this.cityCodeList = result; // 二级城市下分类
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 1500
						})
					}
				} catch (e) {
					uni.showToast({
						title: e,
						icon: 'none',
						duration: 1500
					})
					console.log("e", e)
					//TODO handle the exception
				}
				uni.hideLoading()
			},
		}
	}
</script>
<style lang="scss">
	page {
		height: 100%;


	}

	.font_color {
		@include main_color(theme);
	}

	.container {
		display: flex;
		flex-direction: column;
		height: 100%;
	}

	.header {}

	.content {
		flex: 1;
		overflow: hidden;
	}

	.scroll-view {
		height: 100%;
	}

	// 赠送类型
	.gift-type-card {
		display: flex;
		flex-direction: column;
		padding: 0 20rpx;
		padding-bottom: 20rpx;

		.gift-type {
			display: flex;
			background-color: white;
			padding: 30rpx 20rpx;
			border-radius: 10rpx;

			.gift-type-left {
				font-weight: bold;

			}

			.gift-type-right {
				font-weight: bold;
				display: flex;
				flex-direction: column;
			}
		}
	}

	.scroll-view-inner {

		// 售卖区域
		.sale-area-card {
			display: flex;
			flex-direction: column;
			padding: 0 20rpx;

			.sale-area {
				display: flex;
				background-color: white;
				justify-content: space-between;
				align-items: center;
				padding: 30rpx 20rpx;
				border-radius: 10rpx;

				.sale-area-left {
					font-weight: bold;
				}

				.sae-area-right {
					font-weight: bold;
					display: flex;
					flex-direction: column;
				}
			}
		}



		// 商品活动
		.product-active-card {
			display: flex;
			flex-direction: column;
			padding: 20rpx;

			// 活动时间
			.active-time {
				display: flex;
				justify-content: space-between;
				background-color: white;
				padding: 30rpx 20rpx;
				border-radius: 10rpx;
				border-bottom: 1rpx solid #eee;

				.active-time-left {
					font-weight: bold;
				}

				.active-time-right {
					display: flex;
				}
			}

			// 活动范围
			.product-scope {
				display: flex;
				justify-content: space-between;
				align-items: center;
				background-color: white;
				padding: 30rpx 20rpx;
				border-radius: 10rpx;
				border-bottom: 1rpx solid #eee;

				.product-scope-left {
					font-weight: bold;
				}

				.product-scope-right {
					display: flex;

					.product-type {
						border: 1rpx solid #eaeaea;
						margin-left: 20rpx;
						padding: 10rpx 20rpx;
						border-radius: 10rpx;
					}

					.active {
						border: 1rpx solid;
						@include border_color(theme);
						@include main_color(theme);
					}
				}
			}

			// 单客户限购单数
			.active-limit-card {
				display: flex;
				flex-direction: column;
				background-color: white;
				padding: 30rpx 20rpx;
				border-radius: 10rpx;

				.active-limit-top {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.active-limit-left {
						font-weight: bold;
					}

					.active-limit-right {
						display: flex;
						// justify-content: flex-end;
						justify-content: space-between;

						.active-type {
							border: 1rpx solid #eaeaea;
							padding: 10rpx 20rpx;
							border-radius: 10rpx;
							margin-left: 20rpx;
						}

						.active {
							border: 1rpx solid;
							@include border_color(theme);
							@include main_color(theme);
						}

					}
				}

				.active-limit-bottom {
					display: flex;
					display: flex;
					justify-content: flex-end;
					padding: 20rpx 0;
				}

			}
		}

		// 优惠阶梯
		.discounts-card {
			.discounts-item {
				display: flex;
				flex-direction: column;
				margin: 0 20rpx;
				margin-bottom: 20rpx;
				padding: 0 20rpx;
				background-color: white;


				.discounts-item-title {
					padding: 20rpx 0;
					font-weight: bold;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.item-title-left {}

				}

				.discounts {
					display: flex;
					flex-direction: column;
					padding: 30rpx 0rpx;
					border-radius: 10rpx;

					.discounts-top {
						display: flex;
						justify-content: space-between;
						align-items: center;

						.discounts-left {
							font-weight: bold;
						}

						.discounts-right {
							display: flex;
							align-items: center;

							.right-input {
								background-color: #faf8fa;
								padding: 15rpx;
								height: 60rpx;
								margin-right: 20rpx;
							}
						}
					}

					.discounts-bottom {
						display: flex;
						justify-content: flex-end;
						padding: 20rpx 0;
						color: red;
					}

					.productName-bottom {
						display: flex;
						justify-content: flex-end;
						padding: 20rpx 0;
					}

				}
			}
		}

		// 新增阶梯
		.ladder-card {
			background-color: white;
			padding: 35rpx;
			margin: 20rpx;
			text-align: center;
		}


	}

	// 底部按钮
	.footer {
		.bg_color {
			@include main_bg_color(theme);
			color: white;
		}

		.font_color {
			@include main_color(theme)
		}

		.footer-required {
			display: flex;
			align-items: center;
			margin-bottom: 20rpx;
		}

		background-color: white;
		padding: 10rpx 20rpx;
		margin-top: 20rpx;
	}
</style>